import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';

export type ArtworkDocument = Artwork & Document;

@Schema({
    timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
    toJSON: {
        transform: (_, ret) => {
            ret.id = ret._id;
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    }
})
export class Artwork extends Document {
    @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'User' })
    user_id: string;

    @Prop({ required: true })
    title: string;

    @Prop({ default: '' })
    description: string;

    @Prop({ required: true })
    image_url: string;

    @Prop({ required: true })
    thumbnail_url: string;

    @Prop({ type: Object, default: {} })
    generation_params: Record<string, any>;

    @Prop({ required: true })
    workflow_id: string;

    @Prop({ default: 0 })
    view_count: number;

    @Prop({ default: 0 })
    like_count: number;

    @Prop({ default: false })
    is_public: boolean;

    @Prop({ default: [] })
    tags: string[];

    @Prop()
    created_at: Date;

    @Prop()
    updated_at: Date;
}

export const ArtworkSchema = SchemaFactory.createForClass(Artwork); 